import { defineStore } from 'pinia'
import type { LoadingBarApi } from 'naive-ui'

interface GlobalConfigProps {
	loading?: LoadingBarApi
}

export const useGlobalConfig = defineStore('globalStore', {
	state: (): GlobalConfigProps => {
		return {}
	},
	actions: {
		setLoading(loading: LoadingBarApi) {
			this.loading = loading
		},
		startLoading() {
			if (this.loading) {
				this.loading.start()
			}
		},
		finishLoading() {
			if (this.loading) {
				this.loading.finish()
			}
		},
		errorLoading() {
			if (this.loading) {
				this.loading.error()
			}
		}
	}
})
